﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using HumanManagement.BusinessObjects;
using HumanManagement.DataAccess;

namespace HumanManagement.BusinessLogic
{
	public class UserBL
	{

		#region ***** Init Methods ***** 
		UserDA objUserDA;
		public UserBL()
		{
			objUserDA = new UserDA();
		}
		#endregion

		#region ***** Get Methods ***** 
		/// <summary>
		/// Get User by id
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns>User</returns>
		public User GetByID(int id)
		{
			return objUserDA.GetByID(id);
		}

		/// <summary>
		/// Get all of User
		/// </summary>
		/// <returns>List<<User>></returns>
		public List<User> GetList()
		{
			string cacheName = "lstUser";
			if( ServerCache.Get(cacheName) == null )
			{
				ServerCache.Insert(cacheName, objUserDA.GetList(), "User");
			}
			return (List<User>) ServerCache.Get(cacheName);
		}

		/// <summary>
		/// Get DataSet of User
		/// </summary>
		/// <returns>DataSet</returns>
		public DataSet GetDataSet()
		{
			string cacheName = "dsUser";
			if( ServerCache.Get(cacheName) == null )
			{
				ServerCache.Insert(cacheName, objUserDA.GetDataSet(), "User");
			}
			return (DataSet) ServerCache.Get(cacheName);
		}


		/// <summary>
		/// Get all of User paged
		/// </summary>
		/// <param name="recperpage">recperpage</param>
		/// <param name="pageindex">pageindex</param>
		/// <returns>List<<User>></returns>
		public List<User> GetListPaged(int recperpage, int pageindex)
		{
			return objUserDA.GetListPaged(recperpage, pageindex);
		}

		/// <summary>
		/// Get DataSet of User paged
		/// </summary>
		/// <param name="recperpage">recperpage</param>
		/// <param name="pageindex">pageindex</param>
		/// <returns>DataSet</returns>
		public DataSet GetDataSetPaged(int recperpage, int pageindex)
		{
			return objUserDA.GetDataSetPaged(recperpage, pageindex);
		}





		#endregion

		#region ***** Add Update Delete Methods ***** 
		/// <summary>
		/// Add a new User within User database table
		/// </summary>
		/// <param name="obj_user">User</param>
		/// <returns>key of table</returns>
		public int Add(User obj_user)
		{
			ServerCache.Remove("User", true);
			return objUserDA.Add(obj_user);
		}

		/// <summary>
		/// updates the specified User
		/// </summary>
		/// <param name="obj_user">User</param>
		/// <returns></returns>
		public void Update(User obj_user)
		{
			ServerCache.Remove("User", true);
			objUserDA.Update(obj_user);
		}

		/// <summary>
		/// Delete the specified User
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns></returns>
		public void Delete(int id)
		{
			ServerCache.Remove("User", true);
			objUserDA.Delete(id);
		}
		#endregion
	}
}
